1. Field of Invention
This invention relates generally to computing systems. Specifically, provides a method and system for selectively calculating any of the 12 pairs of Porter-Duff equations using a single efficient block of code.
2. Description of Related Art
Computer generated images are typically made up of many differing components or graphical elements which are “composited” (or rendered together) to create a final image. Techniques of compositing objects, which include transparency, to create a final image are well-known in the art. In a first conventional method, which derives from the “painter's algorithm”, each object is normally “rendered” to create a corresponding pixel representation. The pixel representation is normally utilized in building up a final image of the objects through combining it with the representation of other objects.
An image is separated into its constituent elements so that they can be independently rendered, thereby potentially saving large amounts of time due to the use of smaller image fragments. Each element or object has associated with it a particular matte or “Alpha Channel” information which generally includes coverage information designating the shape and transparent nature of the element. The matte or Alpha Channel information is normally stored separately for each pixel. Each pixel normally stores the color components (for example Red, Green, Blue (RGB)). Therefore, each pixel of an element can be represented by the quadruple (R,G,B,.alpha.) where .alpha. represents the transparency of an element and is known generally as the “Alpha” or opacity channel. As an example, if black is represented by the RGB color components (0,0,0), then the color black can be represented by the quadruple (0,0,0,1) and a clear or totally transparent color can be represented by the quadruple (0,0,0,0).
Thomas Porter and Tom Duff, in an article entitled “Compositing Digital Images” appearing in Computer Graphics, Vol. 18, No. 3, July 1984 at pages 253–259, which is incorporated by reference in its entirety for all purposes, set out a method for compositing elements together to form “super-elements” as well as discuss methods of combining two images wherein both images have an “alpha.” channel. As described therein, there are 12 main compositing operations for combining two portions of a single image. The alpha values specify either the opacity of the pixel or how much of a particular pixel is covered by the color of that particular pixel. In this way, alpha values are useful in creating digital image mixing effects when combining images through a process often referred to as alpha compositing.
There are many well known ways in which the alpha value of a pixel can be used to control how the colors of the pixels are combined. Porter and Duff defined 12 rules for how to combine the colors of two pixels based upon their respective alpha values. In defining these rules, Porter and Duff also defined the mathematics involved in using the respective alpha values to calculate “fraction values” which are multiplied with the color values of the two pixels before adding the fractional colors together. In so doing, 24 equations are required for turning the alpha value of one pixel into a fraction for the color values of the other pixel.
In order to implement a blending operation that can calculate any of the 12 standard Porter-Duff rules, it would be necessary to code for calculating the result of each of the 24 equations and then multiply by the resulting fractions and then add the values together to get the blended result. This approach would require some way to switch in the appropriate calculation into the blending algorithm depending on which rule is to be used resulting in either repeating the entire blending function 12 times each with a different pair of equations or adding a decision tree so that one copy of the function can perform any of the rules by deciding for each pair of pixels which equation must be performed. Unfortunately, however, the former choice results in a large increase in application size due to repeating the shared code of the blending operation while the latter choice results in a large body of code with decisions in the innermost loop that slow down the per-pixel blending speed.
Therefore what is desired is a method and system for selectively calculating any of the 12 pairs of Porter-Duff equations using a single efficient block of code.